<?php
/**
 * 数据示例
 *
 * Author: Zeon
 * Date: 2017/7/21
 * Time: 16:24
 * Created by PhpStorm.
 */

namespace App\Services\OpenWechat;


class Mock
{
    /**
     * 授权公众号取消
     *
     * @return array
     */
    public function authorizeCancelEvent()
    {
        // $event->all()
        $event_all = [
            'AppId'           => 'wxf89bd554b5dc915a',
            'CreateTime'      => '1511418104',
            'InfoType'        => 'unauthorized',
            'AuthorizerAppid' => 'wx772f215981b8917e',
        ];

        return $event_all;
    }

    /**
     * 公众号授权
     *
     * @return array
     */
    public function authorizeEvent()
    {
        $event_all = [
            'AppId'                        => 'wxf89bd554b5dc915a',
            'CreateTime'                   => '1511417429',
            'InfoType'                     => 'authorized',
            'AuthorizerAppid'              => 'wx772f215981b8917e',
            'AuthorizationCode'            => 'queryauthcode@@@xC6fH96PStPBzepque3Xk4kv1RlLo49sZjUkyFHBwaLLs-iAxmTo96OIjt3rfFxpeYAZ0LInbp5jtngfdWV_ZA',
            'AuthorizationCodeExpiredTime' => '1511421029',
            'PreAuthCode'                  => 'preauthcode@@@oFrRCARwxP-jFd46zUvNpPHiwZqgNCJE_ErWHDYtC5TaQZNhOwh-xXrMlCmxf2Vs',
        ];


        return $event_all;
    }

    /**
     * 公众号授权事件示例
     *
     * @return array
     */
    public function verifyTicketEvent()
    {
        $event_all = [
            'AppId'                 => 'wxf89bd554b5dc915a',
            'CreateTime'            => '1511417417',
            'InfoType'              => 'component_verify_ticket',
            'ComponentVerifyTicket' => 'ticket@@@fkhgt5YvZcF3PxXX8CSgFwQW6MpDkpRTqMT_BxfX05l__pijvyMW4UZf4PKCf0-IvictYvPn-IHMoQ0O2nsldA',
        ];

        return $event_all;
    }

    /**
     * 授权公众号更新
     *
     * @return array
     */
    public function authorizeUpdateEvent()
    {
        // $event->all()
        $event_all = [
            'AppId'                        => 'wxf89bd554b5dc915a',
            'CreateTime'                   => '1511418002',
            'InfoType'                     => 'updateauthorized',
            'AuthorizerAppid'              => 'wx772f215981b8917e',
            'AuthorizationCode'            => 'queryauthcode@@@xC6fH96PStPBzepque3Xk4kv1RlLo49sZjUkyFHBwaLLs-iAxmTo96OIjt3rfFxpeYAZ0LInbp5jtngfdWV_ZA',
            'AuthorizationCodeExpiredTime' => '1511421602',
            'PreAuthCode'                  => 'preauthcode@@@oFrRCARwxP-jFd46zUvNpPHiwZqgNCJE_ErWHDYtC5TaQZNhOwh-xXrMlCmxf2Vs',
        ];

        return $event_all;
    }

    /**
     * Collection $open_wx->getAuthorizationInfo($appid);
     *
     * @return array
     */
    public function openWxGetAuthorizationInfo()
    {
        /**
         * $info->all()
         */
        $authorizationInfo_all = [
            'authorization_info' =>
                [
                    'authorizer_appid'         => 'wx772f215981b8917e',
                    'authorizer_access_token'  => '0qK1s5qJpLteLs_3S2lfH92t_91a89X_ck8pRjPwx3a9ty0Qfsb6nD1Hm0KsKGyA6UE71foS3wUSjMQUzeUwA8wNczy3eUjJSiSY7QM7uqVc_AvbRfoiKeBkGQ1RcBhrISLcAMDXHA',
                    'expires_in'               => 7200,
                    'authorizer_refresh_token' => 'refreshtoken@@@OLdFSZMeEzHaw1S54QcZY0blPRntTC2pAcFYPSumCWY',
                    'func_info'                => [['funcscope_category' => ['id' => 1,]], ['funcscope_category' => []],]
                ]
        ];

        return $authorizationInfo_all;
    }


    /**
     * Collection $open_wx->getAuthorizer($appid);
     *
     * @return array
     */
    public function openWxGetAuthorizerInfo()
    {
        $info_all = [
            "authorizer_info"    => [
                "nick_name"         => "小镜秀秀服务号1_本地测试",
                "head_img"          => "http=>//wx.qlogo.cn/mmopen/nBeHhd0TC8V3A2nQicd6pGFGNycjl7DBYAlaBj5icicbv3rEIOz1ljFAnI369pKIh10heatbLwpG7sCRTOQs1uu0JCWGXp6m97b/0",
                "service_type_info" => [
                    "id" => 2,
                ],
                "verify_type_info"  => [
                    "id" => 0,
                ],
                "user_name"         => "gh_7c996c01e83a",
                "alias"             => "",
                "qrcode_url"        => "http://mmbiz.qpic.cn/mmbiz_jpg/zbLmIZvRibazzmPhS77gsia4nVm8rVVWSpSLcuftNtbCqq1OzbiaBsDe58RPFE4LWFhlmeho2REZpErbiaQ7icRk3Cw/0",
                "business_info"     => [
                    "open_pay"   => 1,
                    "open_shake" => 0,
                    "open_scan"  => 0,
                    "open_card"  => 1,
                    "open_store" => 0,
                ],
                "idc"               => 1,
                "principal_name"    => "广州帕克西软件开发有限公司",
                "signature"         => "小镜秀秀3D虚拟试穿试戴系统致力于打通线上线下体验，提供完整的虚拟试穿试戴解决方案，为眼镜、服装等穿戴产品的电子商务营销提供强有力支持。",
            ],
            "authorization_info" => [
                "authorizer_appid"         => "wx772f215981b8917e",
                "authorizer_refresh_token" => "refreshtoken@@@OLdFSZMeEzHaw1S54QcZY0blPRntTC2pAcFYPSumCWY",
                "func_info"                => [
                    [
                        "funcscope_category" => [
                            "id" => 1,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 15,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 4,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 7,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 2,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 3,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 11,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 6,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 5,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 8,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 13,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 9,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 10,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 12,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 22,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 23,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 24,
                        ],
                        "confirm_info"       => [
                            "need_confirm"    => 0,
                            "already_confirm" => 0,
                            "can_confirm"     => 0,
                        ],
                    ],
                    [
                        "funcscope_category" => [
                            "id" => 26,
                        ],
                    ],
                ],
            ],
        ];

        return $info_all;
    }

    /**
     * 微信用户数据(未关注公众号，用网页oauth接口返回的信息)
     *
     * @internal \Overtrue\Socialite\User $user
     * @example
     *      $user->getOriginal()
     *
     * @return array
     */
    public static function userGetOriginal()
    {
        $original = [
            "openid"     => "onjGlwrieApWklBJx-NxX_KnuOQw",
            "nickname"   => "\u552f\u4f9d\u8a93\u7ea6",
            "sex"        => 1,
            "language"   => "zh_CN",
            "city"       => "\u76d8\u9526",
            "province"   => "\u8fbd\u5b81",
            "country"    => "\u4e2d\u56fd",
            "headimgurl" => "http:\/\/wx.qlogo.cn\/mmopen\/USHiacTvibI9dhoIaydNYazOicibAqcicnM8KwE9tVnhWKtGdSowcEkicSHkX030djlDeqDmWRutVIjX1z9xtmZvYUrL7mibOEcg08G\/0",
            "privilege"  => ["chinaunicom"],
        ];

        return $original;
    }
    
    public static function userGetOriginalFailed()
    {
        return $error = [
            'errcode' => 40001,
            'errmsg' => 'invalid credential, access_token is invalid or not latest, hints: [ req_id: hV6eHa0279hb25 ]',
        ];
    }

    /**
     * 已关注公众号时，通过返回的微信用户数据
     *
     * @internal EasyWeChat\Foundation\Application $app
     * @internal Overtrue\Socialite\User $user
     * @example
     *      $app->user->get($user->getId());
     *
     */
    public static function appUserGet()
    {
        $all = [ // 已关注公众号的用户，用微信用户查询接口返回的信息
            "subscribe"       => 1,
            "openid"          => "onjGlwrieApWklBJx-NxX_KnuOQw",
            "nickname"        => "唯依誓约",
            "sex"             => 1,
            "language"        => "zh_CN",
            "city"            => "盘锦",
            "province"        => "辽宁",
            "country"         => "中国",
            "headimgurl"      => "http => \/\/wx.qlogo.cn\/mmopen\/USHiacTvibI9dhoIaydNYazOicibAqcicnM8KwE9tVnhWKtGdSowcEkicSHkX030djlDeqDmWRutVIjX1z9xtmZvYUrL7mibOEcg08G\/0",
            "subscribe_time"  => 1492399467,
            "remark"          => "",
            "groupid"         => 0,
            "tagid_list"      => [],
            'subscribe_scene' => 'ADD_SCENE_QR_CODE',
            'qr_scene'        => 0,
            'qr_scene_str'    => '',
        ];

        return $all;
    }

    /**
     * 错误的 openid
     *
     * @return array
     */
    public static function appUserGetInvalidOpenId()
    {
        return [
            "errcode" => 40003,
            "errmsg"  => "invalid openid hint: [tvNmPa0007sha5]",
        ];
    }

    /**
     * 已关注公众号时，通过返回的微信用户数据（未关注/已取关公众号）
     *
     * @internal EasyWeChat\Foundation\Application $app
     * @internal Overtrue\Socialite\User $user
     * @example
     *      $app->user->get($user->getId());
     *
     */
    public static function appUserUnSubscribedGet()
    {
        $all = [
            "subscribe"  => 0,
            "openid"     => "onjGlwrieApWklBJx-NxX_KnuOQw",
            "tagid_list" => [],
        ];

        return $all;
    }

    /**
     * 公众号服务器推送消息(文字消息)
     * @internal Collection $message -> all()
     * @return array
     */
    public static function serverTextMessage()
    {
        $message_all = [
            // 微信用户发来的文字
            "Content"      => "测试文字",
            "CreateTime"   => "1480300157",
            // open id
            "FromUserName" => "oc0iSwfuKUkMiAb86DnPSzUd8ocM",
            "MsgId"        => "6357840762989642150",
            "MsgType"      => "text",
            // 公众号原始 ID
            "ToUserName"   => "gh_7c996c01e83a",
        ];

        return $message_all;
    }

    /**
     * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140841
     * @return array
     */
    public static function serverLocationEventMessage()
    {
        $message_all = [
            "ToUserName"   => "开发者 微信号",
            "FromUserName" => "发送方帐号（一个OpenID）",
            "CreateTime"   => "消息创建时间 （整型）",
            "MsgType"      => "消息类型，event",
            "Event"        => "事件类型，LOCATION",
            "Latitude"     => "地理位置纬度",
            "Longitude"    => "地理位置经度",
            "Precision"    => "理位置精度地",
        ];

        return $message_all;
    }

    /**
     * 公众号服务器推送消息(点击菜单跳转View)
     * @internal Collection $message -> all()
     * @return array
     */
    public static function serverEventViewMessage()
    {
        $message_all = [
            'ToUserName'   => 'gh_7c996c01e83a',
            'FromUserName' => 'oc0iSwURExmEgnS-zaXeW-zz-v40',
            'CreateTime'   => '1512006950',
            'MsgType'      => 'event',
            'Event'        => 'VIEW',
            'EventKey'     => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx772f215981b8917e&redirect_uri=http%3A%2F%2Fwemall.xiaojingxiuxiu.com%2Fwemall%2Fwx772f215981b8917e&response_type=code&scope=snsapi_base&state=wemallindex&component_appid=#wechat_redirect',
            'MenuId'       => '418184604',
        ];

        return $message_all;
    }

    /**
     * 公众号服务器推送消息(关注事件)
     * @internal array $message
     * @return array
     */
    public static function serverEventSubscribeMessage()
    {
        $message_all = [
            'ToUserName'   => 'gh_7c996c01e83a',
            'FromUserName' => 'oc0iSwfuKUkMiAb86DnPSzUd8ocM',
            'CreateTime'   => '1512011528',
            'MsgType'      => 'event',
            'Event'        => 'subscribe',
            'EventKey'     => null,
        ];

        return $message_all;
    }


    /**
     * 公众号服务器推送消息(取消关注事件)
     * @internal Collection $message ->all()
     * @return array
     */
    public static function serverEventUnSubscribeMessage()
    {
        $message_all = [
            'ToUserName'   => 'gh_7c996c01e83a',
            'FromUserName' => 'oc0iSwfuKUkMiAb86DnPSzUd8ocM',
            'CreateTime'   => '1512011523',
            'MsgType'      => 'event',
            'Event'        => 'unsubscribe',
            'EventKey'     => null,
        ];

        return $message_all;
    }

    /**
     * 公众号服务器推送消息(扫码事件)
     * @internal array $message
     * @return array
     */
    public static function serverEventScanMessage()
    {
        $message = [
            'ToUserName'   => 'gh_7c996c01e83a',
            'FromUserName' => 'oc0iSwfuKUkMiAb86DnPSzUd8ocM',
            'CreateTime'   => '1512012186',
            'MsgType'      => 'event',
            'Event'        => 'SCAN',
            'EventKey'     => 'MIR_:38',
            'Ticket'       => 'gQGD8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyRGhTWWw3UDhlaTExNkIzRHhxY1AAAgSlWh9aAwQA6QcA',
        ];

        return $message;
    }

    /**
     * 公众号服务器推送消息(地理位置上报)
     * @internal Collection $message ->all()
     * @return array
     */
    public static function serverEventLocationMessage()
    {
        $message_all = [
            'ToUserName'   => 'gh_3c884a361561',
            'FromUserName' => 'ozy4qt5QUADNXORxCVipKMV9dss0',
            'CreateTime'   => '1512099208',
            'MsgType'      => 'event',
            'Event'        => 'LOCATION',
            'Latitude'     => '111.000000',
            'Longitude'    => '222.000000',
            'Precision'    => '333.000000',
        ];

        return $message_all;
    }

    /**
     * 公众号服务器推送消息(扫码关注事件), 注意 EventKey 与上面扫码事件不同
     * @internal Collection $message ->all()
     * @return array
     */
    public static function serverEventScanSubscribeMessage()
    {
        $message_all = [
            'ToUserName'   => 'gh_7c996c01e83a',
            'FromUserName' => 'oc0iSwfuKUkMiAb86DnPSzUd8ocM',
            'CreateTime'   => '1512012307',
            'MsgType'      => 'event',
            'Event'        => 'subscribe',
            'EventKey'     => 'qrscene_GOAT_1',
            'Ticket'       => 'gQGD8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyRGhTWWw3UDhlaTExNkIzRHhxY1AAAgSlWh9aAwQA6QcA',
        ];

        return $message_all;
    }

    /**
     * @return array
     */
    public function qrCode()
    {
        return $result = [
            "ticket"         => "gQHT8DwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAycXlFOXR3NjVjNjQxRXVBWmhxYzEAAgSeabRaAwSAOgkA",
            "expire_seconds" => 604800,
            "url"            => "http://weixin.qq.com/q/02qyE9tw65c641EuAZhqc1",
        ];
    }

    /**
     * @return array
     */
    public function qrCodeErr()
    {
        return $result = [
            "errcode" => 61007,
            "errmsg"  => "api is unauthorized to component hint: [vP2WYa0830vr29!]",
        ];
    }

    /**
     * @return array
     */
    public function setIndustry()
    {
        return [
            'errcode' => 0,
            'errmsg'  => 'ok',
        ];
    }

    /**
     * @return array
     */
    public function setIndustryError()
    {
        return [
            "errcode" => 40102,
            "errmsg"  => "invalid industry id hint: [gWZkuA08953125]"
        ];
    }

    /**
     * 给公众号添加模板，成功返回的数据格式
     *
     * @return array
     */
    public function addTemplate()
    {
        return [
            'errcode'     => 0,
            'errmsg'      => 'ok',
            'template_id' => 'U5j7OgkiAuEZrKIrC8T145_cnWy7eHj5vF3xbeFPHoE',
        ];
    }

    /**
     * 给公众号添加模板，失败返回的数据格式
     *
     * @return array
     */
    public function addTemplateError()
    {
        return [
            'errcode' => 40037,
            'errmsg'  => 'invalid template_id hint: [W67TpA0937vr30]',
        ];
    }

    /**
     * 给公众号添加模板，失败返回的数据格式
     *
     * @return array
     */
    public function addTemplateIndustryError()
    {
        return [
            'errcode' => 45027,
            'errmsg'  => 'template conflict with industry hint: [Ixzo6a01233129]',
        ];
    }

    /**
     * 模板达到上限 26 个不能再申请
     *
     * @return array
     */
    public function addTemplateNumLimit()
    {
        return [
            'errcode' => 45026,
            'errmsg'  => 'template num exceeds limit hint: [c03831960]',
        ];
    }

    /**
     * 查询行业失败 - 模板消息未授权给开放平台
     *
     * @return array
     */
    public function getIndustryError()
    {
        return [
            "errcode" => 61007,
            "errmsg"  => "api is unauthorized to component hint: [YA1Mca03184696!]"
        ];
    }

    /**
     * 未开通模板消息
     *
     * @return array
     */
    public function getIndustry()
    {
        $it = [ // 单 IT 行业
            "primary_industry"   => [
                "first_class"  => "IT科技",
                "second_class" => "互联网|电子商务",
            ],
            "secondary_industry" => [
                "first_class"  => "",
                "second_class" => "",
            ]
        ];

        $double_industry = [ // 存在双行业的情况
            "primary_industry"   => [
                "first_class"  => "IT科技",
                "second_class" => "互联网|电子商务",
            ],
            "secondary_industry" => [
                "first_class"  => "消费品",
                "second_class" => "消费品",
            ]
        ];

        return [
            "primary_industry"   => [ // 单消费品行业
                "first_class"  => "消费品",
                "second_class" => "消费品",
            ],
            "secondary_industry" => [
                "first_class"  => "",
                "second_class" => "",
            ],
        ];
    }
    
    public function appAccessTokenGet()
    {
        return [
          // TODO complete demo response
        ];
    }
}